<?php
namespace Admin\Controller;
use Common\Controller\PublicBaseController;

class LoginController extends PublicBaseController{

    /**
     * 登录
     */
    public function login(){
        if(IS_POST){
            // 做一个简单的登录 组合where数组条件
            $data=I('post.');

            if(check_verify($data['verify'])){
                $map['username']=$data['username'];
                $map['password']=md5($data['password']);

                $data1=M('Users')->where($map)->find();
                if (empty($data1)) {
                    $this->error('账号或密码错误');
                }else{
                    $_SESSION['user']=array(
                        'id'=>$data1['id'],
                        'username'=>$data1['username'],
                        'avatar'=>$data1['avatar']
                    );
                    $this->success('登录成功、前往管理后台',U('Admin/Index/index'));
                }
            } else{
                $this->success('验证码输入错误',U('Admin/Login/login'));
            }

        }else{
            $this->display();
        }

    }

    /**
     *
     */
    // 生成验证码
    public function showVerify(){
        show_verify();
    }
}